package com.it.controller;

import com.it.pojo.Classes;
import com.it.pojo.Team;
import com.it.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TeamController {

    @Autowired
    private TeamService teamService;

    @RequestMapping("/group")
    public List<Team> selectByGroup(Integer classes){
        return teamService.getAll(classes);
    }

    @RequestMapping("/addTeam")
    public String addTeam(@RequestBody Team team) {
        if (team.getCid() == null) {
            return "请选择班级";
        } else {
            teamService.add(team);
            return null;
        }
    }

    @RequestMapping("/editTeam")
    public void editTeam(@RequestBody Team team) {
        teamService.update(team);
    }

    @RequestMapping("/delTeam/{id}")
    public void delTeam(@PathVariable Integer id) {
        teamService.delete(id);
    }

}
